//
//  UserInfoRequest.m
//  BaseProject
//
//  Created by 王洋 on 2021/2/1.
//  Copyright © 2021 王洋. All rights reserved.
//

#import "UserInfoRequest.h"

@implementation UserInfoRequest

//更新最新的用户信息数据
+ (void)request_userInfoComption:(void (^)(BOOL success, UserInfoModel *model))comption {

    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:[TTUserModel sharedObject].userId forKey:@"userId"];
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_MyInfo];

    NSLog(@"请求用户信息");
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        
        if ([data isKindOfClass:[NSDictionary class]]) {
            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                NSDictionary *resultDic = [data valueForKey:@"data"];
                //NSLog(@"请求用户信息返回-%@",data);

                UserInfoModel *model = [UserInfoModel modelWithDictionary:resultDic];
                [[TTUserModel sharedObject].userModelDefault setValue:model.imgUrl forKey:@"TT_userIcon"];
                [[TTUserModel sharedObject].userModelDefault setValue:@(model.sex) forKey:@"TT_sex"];
                [[TTUserModel sharedObject].userModelDefault setValue:model.autograph forKey:@"TT_autograph"];
                
                [[TTUserModel sharedObject].userModelDefault setValue:model.wechatNo forKey:@"TT_wechatNo"];

                [[TTUserModel sharedObject].userModelDefault setValue:model.marryTime forKey:@"TT_marryTime"];
                [[TTUserModel sharedObject].userModelDefault setValue:model.nickname forKey:@"TT_nickname"];
                [[TTUserModel sharedObject].userModelDefault synchronize];

                [TTUserModel sharedObject].timeTag = [Utilities getCurrentTimestamp];
                comption(YES,model);
            } else {
                comption(NO,nil);
            }
        } else {
            comption(NO,nil);
        }
        
    } FailedBlock:^(NSError * _Nonnull error) {
        comption(NO,nil);
    }];
    
    
}
@end
